set RECV_LISTEN(PART) m_part
set RECV_LISTEN(JOIN) m_join

proc m_part {chid raw parent me} {
	global CHANS_$chid
	
	set reason ""
	regexp {:([^!]+)![^@]+@[^ ]+ PART ([^ ]+)} $raw -> nick channel
	regexp {:([^!]+)![^@]+@[^ ]+ PART ([^ ]+) :(.+)} $raw -> nick channel reason
	set num [set "CHANS_$chid\([string tolower $channel]\)"]
	if { "$nick" == "$me" } {
		deleteoutput $parent.chan$num
	} else {
		if [string length $reason] {
			output $parent.chan$num "<- $nick [tr {has parted}] $channel ($reason)\n" grey39
		} else {
			output $parent.chan$num "<- $nick [tr {has parted}] $channel\n" grey39
		}
		raw $chid "NAMES $channel"
	}
}

proc m_join {chid raw parent me} {
	global CHANS_$chid
	global UHOSTS
	
	regexp {:([^!]+)!([^@]+)@(.+)} [lindex $raw 0] -> nick user host
	regexp {:(.+)} [lindex $raw 2] -> channel
	
	if { "$nick" == "$me" } {
		set chanschid "CHANS_$chid\([string tolower $channel]\)"
		set $chanschid [llength [array names CHANS_$chid]]
		set num [set "CHANS_$chid\([string tolower $channel]\)"]
		createoutput $parent.chan$num "$channel" $chid
	} else {
		raw $chid "NAMES $channel"
		set num [set "CHANS_$chid\([string tolower $channel]\)"]
	}
	
	output $parent.chan$num "-> $nick [tr {has joined}] $channel\n" grey39
	set UHOSTS($nick) "$user@$host"
}
